package network.UDP;

import java.io.IOException;
import java.net.*;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-04-05
 * Time:16:38
 */
public class Sender {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(8888);
        byte[] bytes = "Hello Receiver!".getBytes();
        DatagramPacket packet = new DatagramPacket(bytes, 0, bytes.length, InetAddress.getLocalHost(), 9999);
        socket.send(packet);
        //===============================================
        byte[] buf = new byte[1024 * 54];
        packet = new DatagramPacket(buf,buf.length);
        socket.receive(packet);
        byte[] data = packet.getData();
        int len = packet.getLength();
        String string = new String(data, 0, len);
        System.out.println(string);
        socket.close();
    }
}
